import { Router } from "express";
import { IcallbackFn, Ioracle } from "../../types";

//获取宿舍调整数据
export default (router: Router, oracle: Ioracle, callbackFn: IcallbackFn) => {
  router.post("/getMoveData",(_req, res)=>{
    const { worknum } = _req.body
    let sql = "select a.badge_no,decode(a.action_category,'寢室調整','入住')action_category,a.old_line_id,a.new_line_id,a.last_update_by,a.last_update_date,a.liveout_date,a.livein_date"
    sql += " ,b.room_num,b.bed_num,c.dorm_name"
    sql += " from xx_g00_bed_activity a,xx_g00_bed b,xx_g00_drom c"
    sql += " where a.new_line_id = b.line_id and a.old_line_id is null"
    sql += " and b.header_id = c.header_id  "
    sql += " and badge_no = '" + worknum + "'"
    sql += " union"
    sql += " select a.badge_no,a.action_category,a.old_line_id,a.new_line_id,a.last_update_by,a.last_update_date,a.liveout_date,a.livein_date"
    sql += " ,b.room_num,b.bed_num,c.dorm_name"
    sql += " from xx_g00_bed_activity a,xx_g00_bed b,xx_g00_drom c"
    sql += " where a.old_line_id = b.line_id "
    sql += " and b.header_id = c.header_id "
    sql += " and badge_no = '" + worknum + "'"
    sql += " order by livein_date"
    callbackFn( res, oracle.connChaos,{sql})
  })

  return router
}